/**
 * Created by tuyan on 2016/11/28.
 */
/**
 * Created by tuyan on 2016/11/27.
 */
/**
 * 定义全局框架对象
 *
 * @type {{}}
 */
window.Cherry = {};

/**
 * 全局方法封装.
 */
$.extend(Cherry, {

    CONTENT_RENDER: "page-wrapper",

    /**
     * 验证错误提示图标
     */
    ERROR_ICON: "<i class='fa fa-times-circle'></i>",

    /**
     * 资源权限
     */
    METADATA_AUTHORITY: {},
    ADD: 'ADD', //新增
    EDIT: 'EDIT',   //修改
    DELETE: 'DELETE',   //删除
    SAVE: 'SAVE',   //保存
    SELECT: 'SELECT',   //查看
    ENABLE: 'ENABLE',   //启用
    DISABLE: 'DISABLE',   //禁用
    ADD1: 'ADD1',   //新增1
    EDIT1: 'EDIT1',   //修改1
    DELETE1: 'DELETE1',   //删除1
    DEAL:'DEAL',  //处理
    DISTRIBUTE:'DISTRIBUTE',                    //分发
    INFO_REMAIN:'INFOREMAIN',                   //短信提醒
    ASSIGN:'ASSIGN',                            //分派
    BACK:'BACK',                                //归档
    ADD_POST:'ADDPOST',                         //发送
    BTNDISTRIBUT:'BTNDISTRIBUT',                //本级分派/处理
    QUICKDISTRIBUT:'QUICK_DISTRIBUT',           //快速分派
    PUBLISH:'PUBLISH',                          //发布
    INFORBACK:'INFORBACK',                      //撤回
    PASSINFO:'PASSINFO',                        //审核通过
    UNPASSINFO:'UNPASSINFO',                    //审核不通过
    COMMENT:'COMMENT',                          //领导批示
    BTNINFOPOST:'BTN_INFO_POST',              //短信发送
    BTNINFOPOST_AGAIN_E:'BTN_INFO_POST_AGAIN',//再次发送
    BTNSMSREPLY: 'BTNSMSREPLY',     ////短信回复
    BTNINTEREDIT: 'INTEREDIT',     //问题记录
    BTN_CHECK_DEL: 'BTN_CHECK_DEL',//审核/办理
    /**
     * 默认模块
     */
    DEFAULTMODULEID: 'defaultModuleId',

    /**
     * 行政区划类型：0=国家；1=省；2=市；3=区／县
     */
    REGION_TYPE_PRO: 1,
    REGION_TYPE_CITY: 2,
    REGION_TYPE_COUNTY: 3,

    /**
     * 选择型弹出层模版ID
     */
    LAYER_TPL_MODAL: undefined,
    /**
     * 新增弹出层模板ID
     */
    ADD_TPL_MODAL: undefined,

    /**
     * 修改弹出层模板ID
     */
    EDIT_TPL_MODAL: undefined,

    /**
     * 详情弹出层模板ID
     */
    DETAIL_TPL_MODAL: undefined,

    /**
     * 权限弹出层模板ID
     */
    AUTH_TPL_MODAL: undefined,

    /**
     * 树类型
     */
    TREE_TYPE: undefined,
    /**
     * 同一菜单下页面数据缓存数组
     */
    CACHE_IN_MENU: undefined,
    /**
     * 是否为同一菜单下流转标识
     */
    IS_INNER_MENU: 0,
    /**
     * 版本号
     */
    version: '0.0.1',
    /**
     * 是否开启Debug模式
     */
    debug: false,
    /**
     * API服务地址
     */
    apiHost: 'http://127.0.0.1:8289',

    /**
     * 本地服务地址
     */
    // localServerHost: 'http://127.0.0.1:8289',

    /**
     * Resource资源地址
     */
    resHost: 'http://127.0.0.1:80',
    /**
     * 百度富文本编辑器服务端的地址
     */
    baiduUEditorServer: this.apiHost + '/ext/ueditor/cmd',
    /**
     * 新增按钮.
     */
    BTN_ADD: {
        key: "cherry-btn-add",
        title: "新增",
        type: "button",
        icon: "fa-plus",
        className: "btn-orange"
    },

    /**
     * 处理审核按钮.
     */
    BTN_DET_CHECK: {
        key: "cherry-btn-detail",
        title: "处理/审核",
        type: "button",
        icon: "fa-file-text",
        className: "btn-blue"
    },

    /**
     * 分派按钮.
     */
    BTN_ASSIGN: {
        key: "cherry-btn-assign",
        title: "分派",
        type: "button",
        icon: "fa-pencil",
        className: "btn-orange"
    },

    /**
     * 分派按钮.
     */
    BTN_BACK: {
        key: "cherry-btn-back",
        title: "归档",
        type: "button",
        icon: "fa-pencil",
        className: "btn-orange"
    },
    BTN_ADD_POST: {
        key: "cherry-btn-add",
        title: "发送",
        type: "button",
        icon: "fa-plus",
        className: "btn-orange"
    },
    /**
     * 新增全国
     */
    BTN_ADDALL: {
        key: "cherry-btn-addAll",
        title: "新增全国地址",
        type: "button",
        icon: "fa-plus",
        className: "btn-green"
    },

    /**
     * 删除按钮.
     */
    BTN_DEL: {
        key: "cherry-btn-del",
        title: "删除",
        type: "button",
        icon: "fa-minus",
        className: "btn-red"
    },
    /**
     * 短信回复
     */
    BIN_SMS_REPLY: {
        key: "cherry-btn-reply",
        title: "短信回复",
        type: "button",
        icon: "fa-massage",
        className: "btn-green"
    },
    /**
     * 短信提醒
     */
    BTN_INFO_REMAIN: {
        key: "cherry-btn-remain",
        title: "短信提醒",
        type: "button",
        icon: "fa-massage",
        className: "btn-orange"
    },

    /**
     * 短信发送
     */
    BTN_INFO_POST: {
        key: "cherry-btn-quick",
        title: "短信发送",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },
    /**
     * 短信发送
     */
    BTN_INFO_POST_AGAIN: {
        key: "cherry-btn-post",
        title: "再次发送",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },
    /**
    /**
     * 快速分派按钮.
     */
    BTN_QUICK_DISTRIBUT: {
        key: "cherry-btn-quick",
        title: "快速分派",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },
    /**
     * 本级分派/处理按钮.
     */
    BTN_DISTRIBUT: {
        key: "cherry-btn-distribut",
        title: "本级分派/处理",
        type: "button",
        icon: "fa-pencil",
        className: "btn-blue"
    },

    /**
     * 发布
     */
    BTN_INFO_PUBLISH: {
        key: "cherry-btn-publish",
        title: "发布",
        type: "button",
        icon: "fa-pencil",
        className: "btn-blue"
    },
    /**
     *撤销
     */
    BTN_INFO_RBACK: {
        key: "cherry-btn-back",
        title: "撤销",
        type: "button",
        icon: "fa-pencil",
        className: "btn-orange"
    },

    /**
     * 修改按钮.
     */
    BTN_INTEREDIT: {
        key: "cherry-btn-interface",
        title: "问题记录",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },

    /**
     * 修改按钮.
     */
    BTN_EDIT: {
        key: "cherry-btn-edit",
        title: "修改",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },

    /**
     * 管理按钮.
     */
    BTN_MANAGE: {
        key: "cherry-btn-manage",
        title: "管理",
        type: "button",
        icon: "fa-pencil",
        className: "btn-blue"
    },

    /**
     * 重置密码.
     */
    BTN_RESET: {
        key: "cherry-btn-reset",
        title: "重置密码",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },

    /**
     * 回复按钮.
     */
    BTN_REPLY: {
        key: "cherry-btn-reply",
        title: "回复",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },

    /**
     * 处理按钮
     */
    BTN_DEAL: {
        key: "cherry-btn-deal",
        title: "处理",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },

    /**
     * 查看详情按钮.
     */
    BTN_CHECK_DEL: {
        key: "cherry-btn-detail",
        title: "审核/办理",
        type: "button",
        icon: "fa-file-text",
        className: "btn-blue"
    },

    /**
     * 查看详情按钮.
     */
    BTN_DETAIL: {
        key: "cherry-btn-detail",
        title: "详情",
        type: "button",
        icon: "fa-file-text",
        className: "btn-blue"
    },
    BTN_DISTRIBUTE: {
        key: "cherry-btn-distribute",
        title: "分发",
        type: "button",
        icon: "fa-pencil",
        className: "btn-orange"
    },
    BTN_SEIZED: {
        key: "cherry-btn-seized",
        title: "受理",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },
    BTN_CHECK_IN: {
        key: "cherry-btn-check-in",
        title: "办理",
        type: "button",
        icon: "fa-file-text",
        className: "btn-blue"
    },
    BTN_FINISH: {
        key: "cherry-btn-finish",
        title: "办结",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },
    CONFIRM_PROCEEDS: {
        key: "cherry-btn-proceeds",
        title: "确认收款",
        type: "button",
        icon: "fa-file-text",
        className: "btn-blue"
    },
    /**
     * 审核按钮.
     */
    CHOOSE: {
        key: "cherry-btn-examine",
        title: "选择",
        type: "button",
        icon: "fa-file-text",
        className: "btn-orange"
    },

    /**
     * 审核按钮.
     */
    BTN_EXAMINE: {
        key: "cherry-btn-examine",
        title: "审核",
        type: "button",
        icon: "fa-file-text",
        className: "btn-blue"
    },

    /**
     * 启用按钮.
     */
    BTN_ENABLE: {
        key: "cherry-btn-enable",
        title: "启用",
        type: "button",
        icon: "fa-eye",
        className: "btn-blue"
    },

    /**
     * 禁用按钮.
     */
    BTN_DISABLE: {
        key: "cherry-btn-disable",
        title: "禁用",
        type: "button",
        icon: "fa-eye-slash",
        className: "btn-blue"
    },

    /**
     * 审核通过.
     */
    BTN_PASS: {
        key: "cherry-btn-pass",
        title: "审核通过",
        type: "button",
        icon: "fa-file-text",
        className: "btn-blue"
    },

    /**
     * 审核不通过.
     */
    BTN_UNPASS: {
        key: "cherry-btn-unpass",
        title: "审核不通过",
        type: "button",
        icon: "fa-file-text",
        className: "btn-blue"
    },
    /**
     * 审核不通过.
     */
    BTN_COMMENT: {
        key: "cherry-btn-comment",
        title: "领导批示",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },
    /**
     * 导出按钮
     */
    BTN_EXPORT: {
        key: "cherry-btn-export",
        title: "导出",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },
    /**
     * 导入按钮
     */
    BTN_IMPORT: {
        key: "cherry-btn-import",
        title: "导入",
        type: "button",
        icon: "fa-pencil",
        className: "btn-red"
    },
    /**
     * 查看值按钮.
     */
    BTN_VAL: {
        key: "cherry-btn-val",
        title: "值",
        type: "button",
        icon: "fa-file-text",
        className: "btn-blue"
    },
    /**
     * 店铺广告管理按钮.
     */
    BTN_ADD_SELLER_STORE_AD_INFO: {
        key: "cherry-store-ad-info",
        title: "店铺广告管理",
        type: "button",
        icon: "fa-plus",
        className: "btn-blue"
    },

    /**
     * 设置商品属性
     */
    BTN_ATTR: {
        key: "cherry-btn-attr",
        title: "设置属性",
        type: "button",
        icon: "fa-file-text",
        className: "btn-blue"
    },

    /**
     * 商品图片管理
     */
    BTN_PICTURE: {
        key: "cherry-btn-picture",
        title: "图片管理",
        type: "button",
        icon: "fa-picture-o",
        className: "btn-orange"
    },
    /**
     * 商品上架
     */
    BTN_SKUPUTAWAY: {
        key: "cherry-btn-skuputaway",
        title: "商品上架",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },
    /**
     * 商品下架
     */
    BTN_SKUSOLDOUT: {
        key: "cherry-btn-skusoldout",
        title: "商品下架",
        type: "button",
        icon: "fa-pencil",
        className: "btn-red"
    },
    /**
     * 确认发货
     */
    BTN_CONFIRM_DELIVERY: {
        key: "cherry-btn-skusoldout",
        title: "确认发货",
        type: "button",
        icon: "fa-pencil",
        className: "btn-red"
    },

    /**
     * 促销商品
     */
    BTN_PROMOTION_SKU: {
        key: "cherry-btn-addsku",
        title: "添加促销商品",
        type: "button",
        icon: "fa-pencil",
        className: "btn-green"
    },

    /**
     * 导入按钮.
     */
    BTN_IMPORT: {
        key: "cherry-btn-import",
        title: "导入",
        type: "button",
        icon: "fa-plus",
        className: "btn-blue"
    },

    /**
     * 权限分配.
     */
    BTN_AUTH: {
        key: "cherry-btn-auth",
        title: "权限分配",
        type: "button",
        icon: "fa-pencil",
        className: "btn-orange"
    },

    /**
     * 加载一个模版页
     *
     * @param _renderId         渲染的元素ID
     * @param _tpl              模版
     * @param _data             模版数据
     * @param _callbackFunc     加载完成的回调函数
     */
    loadTpl: function(_renderId, _tpl, _data, _callbackFunc) {
        if (!_data) {
            _data = {};
        }
        if(_tpl.indexOf('?')>0){
            var urlJSON = Cherry.getURLParam(_tpl);
            _tpl = _tpl.substr(0,_tpl.indexOf('?'));
            _data = Cherry.mergeJsonObject(_data,urlJSON);
        }
        $("#" + _renderId).html(template(_tpl)(_data));
        if (_callbackFunc) {
            _callbackFunc(_data);
        }
    },/**
     * 两个JSON 对象合并
     * @param jsonbject1     对象1
     * @param jsonbject2     对象2
     * @return resultJsonObject    合并后的Json对象
     */
    mergeJsonObject:function(jsonbject1, jsonbject2) {
        var resultJsonObject={};
        for(var attr in jsonbject1){
            resultJsonObject[attr]=jsonbject1[attr];
        }
        for(var attr in jsonbject2){
            resultJsonObject[attr]=jsonbject2[attr];
        }
        return resultJsonObject;
    },
    /**
     * 打开一个基于模版的模态窗口
     *
     * @param _tpl              模版
     * @param _modalOptions     模态窗口选项
     * @param _modalData        模态窗口数据
     */
    openTplModal: function(_tpl, _modalOptions, _modalData) {
        var _defaultModalOptions = $.extend({
            type: 1,
            skin: 'cherry-form-skin',
            content: template(_tpl)(_modalData),
            btn:false
        }, _modalOptions);
        // 弹出窗口
        return layer.open(_defaultModalOptions);
    },
    /**
     * 确认提示
     *
     * @param _message      提示信息
     * @param _yesFunc      点击确认以后的回调函数
     * @param _noFunc       点击取消以后的回调函数
     */
    confirm: function(_message, _yesFunc, _noFunc) {
        layer.confirm(_message, {icon: 3, title: '温馨提示'}, function(index){
            if (_yesFunc) {
                _yesFunc();
            }
            layer.close(index);
        }, function (index) {
            if (_noFunc) {
                _noFunc();
            }
            layer.close(index);
        });
    },
    shenhe: function () {
        Cherry.http.getData(Cherry.apiHost + "/spendingTable/findDb", {pageIndex:1,pageSize:999999}, function (data) {
            var array = data.rows;
            if(array.length<1){
                Cherry.warningTip("没有下一页！", function(){
                    Cherry.loadTpl(Cherry.CONTENT_RENDER, 'biz/financial/backlog/index');
                    layer.close(Cherry.EDIT_TPL_MODAL);
                    layer.close(Cherry.LAYER_TPL_MODAL);
                });
            }
            var html = '';
            for(var i=0;i<array.length && i<10;i++){
                var title = '';
                if(array[i].auditType == 3){
                    title+= '<span style="color:red">['+"驳回"+']</span>'+"  ";
                }else if(array[i].auditType == 4){
                    title+=  '<span style="color:green">['+"完成"+']</span>'+"  ";
                }else
                    title+= '<span style="color:blue">['+"待审"+']</span>'+"  ";
                if(array[i].types == 0)
                    title+= '费用报销单';
                else if(array[i].types == 1)
                    title+=  '差旅费报销单';
                else if(array[i].types == 2)
                    title+=  '借支单';
                else if(array[i].types == 3)
                    title+=  '领款单';

                if(i==0){
                    layer.close(Cherry.LAYER_TPL_MODAL);
                    var data = array[i];
                    if(data.apportionList==null)
                        data.apportion = -1;
                    else {
                        var apportionList = eval(data.apportionList);
                        data.apportion = apportionList[0].instructions;
                    }
                    var array = [];
                    if(data.types==0) {
                        for (var i = 0; i < 5 - data.expenseAccountsList.length; i++) {
                            array[i] = i;
                        }
                        data.array = array;
                        Cherry.LAYER_TPL_MODAL = Cherry.openTplModal('biz/financial/backlog/details', {
                            title: '审核/办理',
                            area: ['98%', '98%']
                        }, data);
                    }else if(data.types==1){
                        for (var i = 0; i < 6 - data.spendingTravelList.length; i++) {
                            array[i] = i;
                        }
                        data.array = array;
                        Cherry.LAYER_TPL_MODAL = Cherry.openTplModal('biz/financial/backlog/travelDetails', {
                            title: '审核/办理',
                            area: ['98%', '98%']
                        }, data);
                    }else if(data.types==2){
                        Cherry.LAYER_TPL_MODAL = Cherry.openTplModal('biz/financial/backlog/jiezhiDetails', {
                            title: '审核/办理',
                            area: ['98%', '98%']
                        }, data);
                    }else if(data.types==3){
                        Cherry.LAYER_TPL_MODAL = Cherry.openTplModal('biz/financial/backlog/lingkuanDetails', {
                            title: '审核/办理',
                            area: ['98%', '98%']
                        }, data);
                    }
                }
            }
        });
    },
    /**
     * 提示.
     *
     * @param _message          提示消息正文
     * @param _icon             提示消息前的图标
     * @param _callbackFunc     提示消息从页面消失以后的回调函数
     */
    tip: function(_message, _icon, _callbackFunc) {
        layer.msg(_message, {icon: _icon}, function(){
            if (_callbackFunc) {
                _callbackFunc();
            }
        });
    },
    /**
     * 成功提示
     *
     * @param _message
     * @param _callbackFunc
     */
    successTip: function(_message, _callbackFunc) {
        layer.msg(_message, {icon: 1, time: 1500}, function(){
            if (_callbackFunc) {
                _callbackFunc();
            }
        });
    },
    /**
     * 警告提示
     *
     * @param _message
     * @param _callbackFunc
     */
    warningTip: function(_message, _callbackFunc) {
        this.tip(_message, 7, _callbackFunc);
    },
    /**
     * 错误提示
     *
     * @param _message
     * @param _callbackFunc
     */
    errorTip: function(_message, _callbackFunc) {
        this.tip(_message, 2, _callbackFunc);
    },
    /**
     * 正在加载提示.
     *
     * @param _message
     */
    loadingTip: function(_message) {
        return layer.msg(_message, {
            icon: 16,
            time: 0
        });
    },
    /**
     * 验证是否为金钱
     * @param _money
     * @returns {boolean}
     */
    isMoney: function(_money) {
        return (/^(([1-9]\d*)|\d)(\.\d{1,2})?$/).test(_money);
    },
    /**
     * 验证是否为数字
     * @param _str
     * @returns {boolean}
     */
    isNumeric: function(_str) {
        return (/^\d+$/).test(_str);
    },
    /**
     * 验证手机号码格式是否合法.
     *
     * @param _mobile
     */
    isMobile: function(_mobile) {
        //return /^(?:13\d|15[89])-?\d{5}(\d{3}|\*{3})$/.test(_mobile);
        return /^1[0-9]{10}$/.test(_mobile);
    },
    /**
     * 验证邮箱格式是否合法
     * @param _email
     * @returns
     */
    isEmail: function(_email){
        return /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(_email);
    },
    /**
     * 验证身份证号码是否合法
     * @param _idcard
     * @returns
     */
    isIdcard: function(_idcard){
        return /^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/.test(_idcard);
    },
    /**
     * 格式化一个数字为金额的显示格式.
     *
     * @param num           要格式化的数字
     * @param precision     小数位保留位数
     * @param separator     整数部分的分隔符
     * @returns {*}
     */
    moneyFormat: function(num, precision, separator) {
        var parts;
        // 判断是否为数字
        if (!isNaN(parseFloat(num)) && isFinite(num)) {
            // 把类似 .5, 5. 之类的数据转化成0.5, 5, 为数据精度处理做准, 至于为什么
            // 不在判断中直接写 if (!isNaN(num = parseFloat(num)) && isFinite(num))
            // 是因为parseFloat有一个奇怪的精度问题, 比如 parseFloat(12312312.1234567119)
            // 的值变成了 12312312.123456713
            num = Number(num);
            // 处理小数点位数
            num = (typeof precision !== 'undefined' ? num.toFixed(precision) : num).toString();
            // 分离数字的小数部分和整数部分
            parts = num.split('.');
            // 整数部分加[separator]分隔, 借用一个著名的正则表达式
            parts[0] = parts[0].toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1' + separator);
            if (parseInt(parts[1]) == 0) {
                return parts[0];
            } else {
                return parts.join('.');
            }
        }
        return NaN;
    },

    /**
     * 表单重置
     * @param formId        表单ID
     */
    reset: function(_formId) {
        //重置输入框，单选框，复选框
        $(':input', '#'+_formId)
            .not(':button, :submit, :reset')
            .val('')
            .removeAttr('selected')
            .removeAttr('checked');
        //重置下拉列表
        $('#'+_formId + ' select').selectpicker('val','').selectpicker('refresh');
    },

    /**
     * 时间范围控件
     * @param _id               事件操作ID
     * @param _startDateId      开始时间隐藏域
     * @param _endDateId        结束时间隐藏域
     * @param _startDate        默认开始时间
     * @param _endDate          默认结束时间
     */
    daterangepicker: function(_id, _startDateId, _endDateId, _startDate, _endDate) {
        var $id = $('#'+_id);
        var $startDateId = $('#'+_startDateId);
        var $endDateId = $('#'+_endDateId);
        _startDate = _startDate && _startDate.length>9 ? _startDate.substring(0,10) : undefined;
        _endDate = _endDate && _endDate.length>9 ? _endDate.substring(0,10) : undefined;
        if($id && $startDateId && $endDateId) {
            $id.daterangepicker({
                format: 'YYYY/MM/DD',//YYYY/MM/DD
                startDate: _startDate ? _startDate : moment().subtract('days', 29),
                endDate: _endDate ? _endDate : moment()
            }, function(start, end) {
                $id.val(start.format('YYYY/MM/DD') + ' - ' + end.format('YYYY/MM/DD'));//YYYY/MM/DD
                $startDateId.val(start.format("YYYY-MM-DD"));//YYYY-MM-DD
                $endDateId.val(end.format("YYYY-MM-DD"));//YYYY-MM-DD
            });

            /*$id.val(_startDate && _endDate ? (_startDate  + ' - ' + _endDate) : (moment().subtract('days', 29).format('YYYY/MM/DD') + ' - ' + moment().format('YYYY/MM/DD')));
            $startDateId.val(_startDate ? _startDate : moment().subtract('days', 29).format('YYYY-MM-DD'));
            $endDateId.val(_endDate ? _endDate : moment().format('YYYY-MM-DD'));*/
            $id.val(_startDate && _endDate ? (_startDate  + ' - ' + _endDate) : '');
            $startDateId.val(_startDate ? _startDate : '');
            $endDateId.val(_endDate ? _endDate : '');
        }
    },
    clickEnter: function (_searchId) {
        //判断是否是回车
        $(document).keypress(function (e) {
            var keyCode = e.keyCode ? e.keyCode : e.which ? e.which : e.charCode;
            if (keyCode == 13) {
                $('#'+_searchId).trigger('click');
            }
        });
    },
    /**
     * 复选框默认选中
     * @param _id               复选框所在标签的id
     * @param _vals             默认选中的值字符串
     * @param _separator        分离器字符
     */
    defaultCheckCheckBox: function(_id, vals, _separator) {
        if (_separator === undefined) {
            _separator = ',';
        }
        var $checkboxs = $("#"+ _id + " input[type='checkbox']");
        var checksArr = vals.split(_separator);
        var $_self;
        $checkboxs.each(function() {
            $_self = $(this);
            checksArr.forEach(function(e){
                if (e == $_self.val()) {
                    $_self.parent().addClass("checked");
                    $_self.attr('checked', true);  // 选中
                    return;  // 结束循环
                }
            })
        });
    },
    /**
     * 获取URL 参数
     * @param URL               xxx?key=value&key=value
     * @reutrn  json        返回参数JSON
     */
    getURLParam:function(_url){
        var paramJSON = {};
        if(_url.indexOf('?')>0){
            var str = _url.substr(_url.indexOf('?')+1,_url.length);
            if(str.indexOf('&')>0){
                var param = str.split('&');
                for(var i = 0;i<param.length;i++){
                    var keyValue = param[i].split('=');
                    paramJSON[keyValue[0]] = keyValue[1];
                }
            }else{
                var param = str.split('=');
                paramJSON[param[0]] = param[1];
            }
        }
        return paramJSON;
    },
    
    getMenuCache:function (_cacheArray) {
        var pageIndex;
        var pageSize;
        _cacheArray.forEach(function (e) {
            var type = e.key;
            var id = e.id;
            if (e.key == 'input') {
                $("#"+id).val( e.value);
            } else if (e.key == "select") {
                $("#" + id ).val(e.value);
                console.log($("#" + id + " option:selected").val());
                $("#"+ id ).selectpicker('refresh');
            }
        });
        table.query();
    },

        setMenuCache:function (_searchId) {
         Cherry.CACHE_IN_MENU = [];
         var inputArray = $("#"+_searchId).find("input");
         inputArray.each(function (index,e) {
            Cherry.CACHE_IN_MENU.push({key:"input",id:e.id,value:e.value});
         });
         var selectArray = $("#"+_searchId).find("select");
         selectArray.each(function (index,e) {
             Cherry.CACHE_IN_MENU.push({key:"select",id:e.id,value:$("#"+e.id+" option:selected").val()});
         });
        Cherry.CACHE_IN_MENU.push({key:"pageIndex",value:$(".page-number.active").children("a").html()});
        var pageSize ;
        var ul = $(".dropdown-menu");
        ul.each(function (index,e) {
            var li = e.childNodes;
            li.forEach(function (e) {
                if(e.className =="active"){
                    pageSize = e.childNodes[0].innerText;
                }
            });
        });
        Cherry.CACHE_IN_MENU.push({key:"pageSize",value:pageSize});

    }

});

